//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections;
using System.Collections.Generic;

namespace OpenLS.Spreadsheet.Expressions
{
    class ArrayValue : IArray
    {
        public ArrayValue(List<List<object>> values)
        {
            _values = values;
        }

        readonly List<List<object>> _values;

        #region IArray Members

        public object this[int row, int column]
        {
            get { return _values[row][column]; }
        }

        public int RowCount
        {
            get { return _values.Count; }
        }

        public int ColumnCount
        {
            get { int result = 0;
                foreach (List<object> l in _values)
                    result = Math.Max(result, l.Count);
                return result ;
            }
        }

        #endregion

        #region IArray Members

       /* public IEnumerable<object> GetEnumerable()
        {
            foreach (List<object> l in _values)
                foreach (object o in l)
                    yield return o;
        }
        */
        #endregion

        public IEnumerator<object> GetEnumerator()
        {
            foreach (List<object> l in _values)
                foreach (object o in l)
                    yield return o;
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}